package com.bw.ivideoproject.wight

import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.widget.Toast
import com.bw.ivideoproject.R
import com.bw.ivideoproject.databinding.BottomdialogDanmuBinding
import com.google.android.material.bottomsheet.BottomSheetDialog

class DanMuBottomDialog(context: Context) : BottomSheetDialog(context) {

    init {
        initView()
    }

    private var onClickListener: OnClickListener? = null

    private lateinit var binding: BottomdialogDanmuBinding

    public fun setOnClickListener(onClickListener:OnClickListener) {
        this.onClickListener = onClickListener
    }

    private fun initView() {
        val view = LayoutInflater.from(context).inflate(R.layout.bottomdialog_danmu, null, false)
        binding = BottomdialogDanmuBinding.bind(view)
        setContentView(binding.root)

        binding.tvBottomdialogDamuClose.setOnClickListener {
            dismiss()
        }

        binding.tvBottomdialogDamuSend.setOnClickListener {
            val toString = binding.etBottomdialogDanmuContent.text.toString()
            if (TextUtils.isEmpty(toString)) {
                Toast.makeText(context, "请输入内容", Toast.LENGTH_SHORT).show()
                return@setOnClickListener
            }
            if (onClickListener != null) {
                onClickListener?.danmuCompleted(toString)
            }
            dismiss()
        }
    }

    interface OnClickListener {
        fun danmuCompleted(content: String)
    }

}